package com.loft.comm.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @ClassName: MD5.java
 * @Author: heb
 * @CreateDate: 2012/03/28
 * @Version: v1.1.0
 * 
 */
public class MD5 {
	/**
	 * @MethodName: doMD5
	 * @Description:MD5加密
	 * @Author: heb
	 * @CreateDate: 2012/03/28
	 */
	public String doMD5(String str) {
		StringBuffer buf = new StringBuffer("");
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(str.getBytes());
			byte b[] = md.digest();
			int i;
			for (int offset = 0; offset < b.length; offset++) {
				i = b[offset];
				if (i < 0)
					i += 256;
				if (i < 16)
					buf.append("0");
				buf.append(Integer.toHexString(i));
			}
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return buf.toString();
	}
}
